﻿using System.Data;
using System.Windows.Forms;

namespace EIM_Accounting
{
    /// <summary>
    /// 共通 成员管理 成员列表
    /// </summary>
    public partial class CM010101 : Form
    {
        public CM010101()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, System.EventArgs e)
        {
            CM010102 cm010102 = new CM010102();
            cm010102.ShowDialog();
        }

        private void btnOut_Click(object sender, System.EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count < 1) { return; }
            string staffId = dataGridView1.SelectedRows[0].Cells["ID"].Value.ToString();

            CM010103 cm010103 = new CM010103("Out", int.Parse(staffId));

            cm010103.ShowDialog();
        }

        private void CM010101_Load(object sender, System.EventArgs e)
        {
            BLL.CM010101 cm010101 = new BLL.CM010101();
            DataSet dsStaff = cm010101.getList();

            dataGridView1.Columns.Add("ID", "编号");
            dataGridView1.Columns.Add("Name", "姓名");

            dataGridView1.Columns.Add("Type", "类别");

            dataGridView1.Columns[0].Width = 100;
            dataGridView1.Columns[1].Width = 200;
            dataGridView1.Columns[2].Width = 100;

            DataTable dt = dsStaff.Tables[0];
            foreach (DataRow dr in dt.Rows)
            {
                DataGridViewRow dgr = new DataGridViewRow();

                foreach (DataGridViewColumn c in dataGridView1.Columns)
                {
                    dgr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);//给行添加单元格
                }

                dgr.Cells[0].Value = dr["ID"];
                dgr.Cells[1].Value = dr["Name"];
                dgr.Cells[2].Value = dr["StaffType"];
                dataGridView1.Rows.Add(dgr);
            }
            //dataGridView1.DataSource = dsStaff.Tables[0];
        }

        private void btnPositive_Click(object sender, System.EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count < 1) { return; }
            string staffId = dataGridView1.SelectedRows[0].Cells["ID"].Value.ToString();

            CM010103 cm010103 = new CM010103("Positive", int.Parse(staffId));

            cm010103.ShowDialog();
        }

        private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.SelectedRows.Count < 1) { return; }
            string staffId = dataGridView1.SelectedRows[0].Cells["ID"].Value.ToString();

            CM010102 cm010102 = new CM010102();
            cm010102.staffId = staffId;

            cm010102.ShowDialog();
        }
    }
}